<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="copyright" content="http://www.appcms.org" />
<link rel="stylesheet" href="skin/base.css">
<link rel="stylesheet" href="skin/talk.css">
<script src="js/zy_control.js"></script>
<script src="js/zy_click.js"></script>
<script src="js/config.js"></script>
<script src="js/common.js"></script>
</head>
<body>
<div id="main" class="loading"> </div>
</body>
<script>
	zy_init();
	var talk_ask_id=0;
	var min=0;
	var isopen = false;
	var page = 1;
	
	function ok_answer(){
		uexWindow.toast("0", "5", '回复成功~', 1000);
		getMain(-1);
	}
	
	function user_talk(userid){
		localStorage['userid'] = userid;
		uexWindow.open('user_talk', '0', 'user_talk.html', 2, '', '', 0);
	}
	
	function audioPlay(url,id){
		uexAudio.closeSoundPool();
		if(!isopen){
			$$(id).className="voice stop";
			uexAudio.open(url);
			uexAudio.play(0);
			isopen = true;
		}else{
			$$(id).className="voice";
			uexAudio.stop();
			isopen = false;
		}
    }
    
	function praise(id){
		if (!c_l()) {
			gologin();
			return false;
		}		
		
		var url = app_path+'index.php?m=iappTalk&c=app&a=praise&id='+id+'&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];	
		uexXmlHttpMgr.open(2,'post',url,"8000");
		uexXmlHttpMgr.send(2);
	}
	
	function ImageBrowser(pictureurls){
		var data= pictureurls.split(","); 
		uexImageBrowser.open(data, 0, 1);
	}
	
	function getMain(t){	
		uexAudio.stop();
		photor = new Array();
		photonum = 0;
		photon = 0;
		talk_ask_id=0;
		if (t == -1) {
			$$('main').className = 'loading';
			page = 1;
		}
		var url = app_path+'index.php?m=iappTalk&c=app&a=show&talkid='+localStorage['talk_id'];
		uexXmlHttpMgr.open(t,'post',url,"8000");
		uexXmlHttpMgr.send(t);
	}
	
	window.uexOnload=function(type){
		if (!type) {
			uexWindow.setBounce("1");
			uexWindow.setBounceParams("0",'{"imagePath":"res://loading.png","textColor":"#666","levelText":"","pullToReloadText":"拖动刷新","releaseToReloadText":"释放刷新","loadingText":"加载中，请稍等"}');
	　　　　	uexWindow.setBounceParams("1",'{"imagePath":"res://loading.png","textColor":"#666","levelText":"","pullToReloadText":"上拉加载更多","releaseToReloadText":"释放加载","loadingText":"加载中，请稍等"}');
	　　　　	uexWindow.showBounceView("0","#f3f3f3","1");
	　　　　	uexWindow.notifyBounceEvent("0","1");
			uexWindow.showBounceView("1","#f3f3f3","1");
　　　　		uexWindow.notifyBounceEvent("1","1");
			uexWindow.onBounceStateChange=function(t,s){
				if(s=="2"){
					if(t=="0"){
						page =1;
						getMain(t);
					}else if(t=="1"){
						reply_list();						
					}
	　　　　　　	}
			}
			
			uexXmlHttpMgr.onData = function(opId, status, data){
				
				uexXmlHttpMgr.close(opId);
				uexWindow.resetBounceView(opId);
				
				if(status==1){
					data=JSON.parse(data);
					//uexWindow.setBounceParams("1",'{"imagePath":"res://loading.png","textColor":"#666","levelText":"上次更新：'+Now()+'","pullToReloadText":"拖动刷新","releaseToReloadText":"释放刷新","loadingText":"加载中，请稍等"}');
					if(opId==0 || opId==-1){//列表
						
						$$('main').innerHTML='';
						
						$$('main').className = '';
						data=data['data'];
						var html ='<div class="talkitem" >';
						html +='<div class="avatar" ontouchstart="zy_touch(\'down\')" onclick="javascript:user_talk('+data['userid']+');">';
						if(data['avatar'].length>10){
							html +='<img src="'+data['avatar']+'">';
						}
						html +='</div>';
				        html +='<div class="talkcontent">'+
				               ' 	<h3>'+data['nickname']+'</h3><div class="date">'+data['addtime']+'  '+data['address']+'</div>';
						
						if(data['photos'].length==1){//单图
				        	html +='<div class="img talkloadimg" ontouchstart="zy_touch(\'down\')" onclick="ImageBrowser(\''+data['photoshd']+'\');">'+
				                   '   <img src="'+data['photos'][0]+'" class="hide" onload="loading(this)">'+
							       '</div>';
						}else if(data['photos'].length>1){//多图
							html +='<div class="imgs">';
							for(n=0;n<data['photos'].length;n++){
				                 html +='<div class="talkloadimg"  ontouchstart="zy_touch(\'down\')" onclick="ImageBrowser(\''+data['photoshd']+'\');"><img src="'+data['photos'][n]+'" class="hide" onload="loading(this)"></div>';
						    }
							html +='<span class="clear"></span></div>';
						}
						if(data['voice']!=''){
							html +='<div class="voice" id="voice'+data['id']+'" ontouchstart="zy_touch(\'down\')" onclick="audioPlay(\''+data['voice']+'\',\'voice'+data['id']+'\');"><span>28”</span></div>';
						}
						
				        html +=' 	<p>'+data['content']+'</p>';
				        html +=' 	<div class="btns"><div class="date"></div>';
						html +=' 		<span class="praiseb" id="praise_'+data['id']+'" ontouchstart="zy_touch(\'down\')" onclick="praise('+data['id']+');">'+data['praise']+'</span>';
						html +=' 	    <span class="commentb" ontouchstart="zy_touch(\'down\')" onclick="commentb('+data['id']+','+data['userid']+',\''+data['nickname']+'\',\''+data['content']+'\');">'+data['renum']+'</span>';
						html +=' 	</div>';
						
						html +='<div id="re_c_'+data['id']+'" class="rec">';
						if(data['praisedata'].length>0){
							html +='<div id="praise_c_'+data['id']+'" class="praise">';
							for(j=0;j<data['praisedata'].length;j++){
								if(j>0){
									html +=',';
								}
								html +=data['praisedata'][j]['nick'];
							}
							html +='等'+data['praise']+'人觉得很赞</div>';
						}else{
							html +='<div id="praise_c_'+data['id']+'"></div>';
						}
			
						html +='</div>';
						
						html +='</div>';
						html +='</div>';
						$$('main').innerHTML= html;
						
						reply_list();
						
					}else if(opId==1){
						if(data['success']=='OK' || data['success']=='NODATA'){
							var list=data['data'];
							for(k in list){
								var div = document.createElement("div");
								div.className='talkitem';
								var html ='';
								html +='<div class="avatar" ontouchstart="zy_touch(\'down\')" onclick="javascript:user_talk('+list[k]['userid']+');">';
								if(list[k]['avatar'].length>10){
									html +='<img src="'+list[k]['avatar']+'">';
								}
								html +='</div>';
						        html +='<div class="talkcontent">';
								html +='    <h3>'+list[k]['nick']+'</h3><div class="date">'+list[k]['addtime']+'  回复      '+list[k]['reply_nick']+'</div>';
								html +=' 	<p>'+list[k]['content']+'</p>';
							    html +=' 	<div class="btns"><div class="date"></div>';
								html +=' 	    <span class="commentb" ontouchstart="zy_touch(\'down\')" onclick="commentb('+list[k]['talkid']+','+list[k]['userid']+',\''+list[k]['nick']+'\',\''+list[k]['content']+'\');">回复</span>';
								html +=' 	</div>';
								html +='</div>';
								div.innerHTML = html;
								$$('main').appendChild(div);
							}
							page++;
						}else{
							uexWindow.toast("0","5",data['msg'],1000);
						}
					}else if(opId==2){//赞
						if(data['success']=='NOTLOGIN'){
							gologin();
						}else if(data['success']=='OK'){
							var pn = parseInt($$("praise_"+opId).innerHTML)+1;
							$$("praise_"+opId).innerHTML=pn;
							$$("praise_"+opId).className="praiseb_yes";
							$$("praise_c_"+opId).className="praise";
							$$("praise_c_"+opId).innerHTML = data['data']['nick']+"等"+pn+"人觉得很赞";
						}else{
							uexWindow.toast("0","5",data['msg'],1000);
						}
					}
				}else if(status == -1){
					if (opId <= 1){
						$$('main').className = 'errer';
						uexWindow.toast("0", "5", '加载失败', 1000);
					}else if (opId > 1) {
						uexWindow.toast("0", "5", '赞失败', 1000);
					}
				}
			}
			
			getMain(-1);
		}
	}
	
	function loading(obj){
		obj.className='';
		var par=obj.parentNode;
		par.className += ' nobg';  
	}
		
	function commentb(id,r_userid,r_nick,content){
		localStorage['answer']='talk_show';
		localStorage['talk_id']=id;
		localStorage['reply_userid']=r_userid;
		localStorage['reply_nick']=r_nick;
		localStorage['talk_content']=content;
		uexWindow.open('talk_answer','0','talk_answer.html','2','', '',0);
	}
	
	function reply_list(){
		var url = app_path+'index.php?m=iappTalk&c=app&a=reply_list&talkid='+localStorage['talk_id']+'&page='+page;
		uexXmlHttpMgr.open(1,'get',url,"8000");
		uexXmlHttpMgr.send(1);
	}
	
	</script>
</html>